{include file="common/header"}
<link href="/static/admin/css/other.css" rel="stylesheet">
<main class="lyear-layout-content">
    <div class="container-fluid">
        <div class="row ant-menu-submenu">
            <div class="col-lg-10 col-b90">
                <div class="card">
                    <div class="right-card-header card-header">
                        <h4>{:lang('set.general_settings')}</h4>
                    </div>
                    <div class="card-body">
                        <div class="example-box set_general">
                            <div class="form-group row">
                                <div class="col-xs-3">
                                    <i class="iconfont icon-dibudaohanglan-"></i>
                                    <span>{:lang('set.message_prompt')}</span>
                                </div>
                                <div class="col-xs-9">
                                    <label class="lyear-switch switch-success">
                                        <input{:checked($general['mess_prompt'],1)} type="checkbox" name="prompt">
                                        <span></span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-xs-3">
                                    <i class="iconfont icon-mobanguanli"></i>
                                    <span>{:lang('set.template_clues')}</span>
                                </div>
                                <div class="col-xs-9">
                                    <label class="lyear-switch switch-success">
                                        <input{:checked($general['mess_clues'],1)} type="checkbox" name="clues">
                                        <span></span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-xs-3">
                                    <i class="iconfont icon-jifenfenpei"></i>
                                    <span>{:lang('set.intelligent_distr')}</span>
                                </div>
                                <div class="col-xs-9">
                                    <label class="lyear-switch switch-success">
                                        <input{:checked($general['mess_distr'],1)} type="checkbox" name="distr">
                                        <span></span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-xs-3">
                                    <i class="iconfont icon-buoumaotubiao19"></i>
                                    <span>{:lang('set.prompt_sound')}</span>
                                </div>
                                <div class="col-xs-6">
                                    <button class="btn btn-label btn-primary" id="upload_file">
                                        <label>
                                            <i class="iconfont icon-shangchuan"></i>
                                        </label>{:lang('public.upload')}
                                        <input type="file" name="upload_file" accept="audio/mpeg,audio/ogg">
                                    </button>
                                    {if !empty($general['mess_mp3'])}
                                    <audio class="play-chat hide">
                                        <source src="{$general['mess_mp3']}" type="audio/mpeg">
                                    </audio>
                                    <button class="btn btn-label btn-primary" onclick="play();">
                                        <label>
                                            <i class="iconfont icon-bofang1"></i>
                                        </label>{:lang('public.play')}
                                    </button>
                                    {/if}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
{include file="common/footer"}
<script type="text/javascript" src="/static/admin/js/set.js"></script>
<script type="text/javascript">
    let IM_config = {
        setGeneral: "{:adminUrl('admin/Set/set_general')}",
        ajaxmp3upfile: "{:apiUrl('api/Upload/ajaxmp3upfile')}",
    };

    $(function () {
        /**
         * 通用设置
         */
        $('.set_general input[type="checkbox"]').click(function () {
            var obj = $(this);
            var data = {
                action: 'open',
                field: obj.attr('name'),
                val: obj.attr('checked')?0:1
            };
            obj.attr('disabled', 'disabled');
            $.post(IM_config.setGeneral, data ,function (r) {
                we_im_msg(r.data);
                if (r.code == 200) {
                    setTimeout(function() {
                        location.reload();
                    },1000);
                }
            });
        });

        /**
         * 上传文件
         */
        $("#upload_file input").change(function() {
            if (!currentvisiid) {
                return false;
            }
            var formData = new FormData();
            formData.append('ajaxupfile', $('input[name="upload_file"]').get(0).files[0]);
            $('input[name="upload_file"]').val('');
            $.ajax({
                url:IM_config.ajaxmp3upfile,
                method: 'post',
                data: formData,
                dataType: 'json',
                processData: false,
                contentType: false,
                cache: false,
                async: false,
                success: function(res) {
                    if (res.errno == 0) {
                        var data = {
                            action: 'mp3',
                            val: res.data[0]
                        };
                        $.post(IM_config.setGeneral, data ,function (res2) {
                            we_im_msg(res2.data);
                            if (res2.code == 200) {
                                setTimeout(function() {
                                    location.reload();
                                },1000);
                            }
                        });
                    }
                }
            });
        });
    });

    function play() {
        $('.play-chat')[0].play();
    }

</script>